<template>
  <div class="app-container">
    <el-button type="primary" @click="addCouponSeries">添加新的优惠卷</el-button>
    <br>
    <br>
    <el-table :data="couponSeriesList" stripe border style="width: 800px">
      <el-table-column label="编号" prop="id" align="center">
        <template slot-scope="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column label="优惠卷名称" prop="name" align="center">
        <template slot-scope="scope">{{ scope.row.name }}</template>
      </el-table-column>
      <el-table-column label="优惠金额" prop="quota" align="center">
        <template slot-scope="scope">{{ scope.row.quota }}</template>
      </el-table-column>
      <el-table-column label="满减" prop="mixLimit" align="center">
        <template slot-scope="scope">{{ scope.row.mixLimit }}</template>
      </el-table-column>
      <el-table-column label="开始日期" prop="startDate" align="center">
        <template slot-scope="scope">{{ scope.row.startTime | timeFilter }}</template>
      </el-table-column>
      <el-table-column label="结束日期" prop="endDate" align="center">
        <template slot-scope="scope">{{ scope.row.endTime | timeFilter }}</template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{row}">
          <el-button type="danger" size="mini" @click="deleteCouponSeries(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { deleteCouponSeries, getCouponSeries } from '@/api/couponSeries'
import { parseTime } from '@/utils/index'

export default {
  filters: {
    timeFilter(time) {
      return parseTime(time, '{y}-{m}-{d}')
    }
  },
  data() {
    return {
      couponSeriesList: null,
      couponSeriesListLoading: true
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.couponSeriesListLoading = true
      getCouponSeries().then(res => {
        this.couponSeriesList = res.data
        this.couponSeriesListLoading = false
        console.info(this.couponSeriesList)
      })
    },
    addCouponSeries() {
      this.$router.push({ path: '/couponSeries/addCouponSeries' })
    },
    deleteCouponSeries(couponSeries) {
      // console.info('delete couponSeries')
      this.$confirm('是否要进行删除操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteCouponSeries(couponSeries).then(response => {
          this.$message.success('删除成功')
          this.fetchData()
        })
      })
    }
  }
}
</script>
<style scoped>

</style>
